
var H5=function(){
    this.id=('h5_'+Math.random()).replace('.','_');
    this.el=$('<div class="h5" id="'+this.id+'">')
    this.page=[];
    $('body').append(this.el)

    this.addPage=function(name,text){
        var page=$('<div class="h5_page section">');
        if(name!=undefined){
            page.addClass('h5_page_'+name);
        }
        if(text!=undefined){
            page.text(text)
        }
        this.el.append(page);
        this.page.push(page);
        return this;
    }
    this.addComponent=function(name,cfg){
        var cfg=cfg||{};
        cfg=$.extend({
            type:'base'
        },cfg)
        var component;
        var page=this.page.slice(-1)[0];
        switch(cfg.type){
            case 'base':
            console.log(name,cfg)
                component=new H5ComponentBase(name,cfg);
                break;
            default:
        }
        page.append(component)
        return this;

    }
    /*h5对象初级化*/
    this.loader=function(firstPage){
        this.el.fullpage({
            onLeave:function(index,nextIndex,direction){
                console.log(11);
                $(this).find('.h5_component').trigger('onLeave')
            },
            afterLoad:function(index,nextIndex,direction){
                // $('#h5').find('.page').eq(index-1).trigger('onLoad')
                $(this).find('.h5_component').trigger('onLoad')
            }
        });
        this.el.show();
        if(firstPage){
            $.fn.fullpage.moveTo(firstPage)
        }

    }
    return this;
}